﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;



namespace H2.NET.Web.Pages
{
    public partial class PTWDQP : TaskPage
    {
        #region 属性 Public

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }

        public string Key
        {
            get
            {
                return ViewState["Key"] == null ? "" : (string)ViewState["Key"];

            }
            set { ViewState["Key"] = value; }
        }

        private string[] Sales_Office
        {
            get
            {
                if (StoreAPI["Sales_Office~" + Key] == null)
                {

                    IList<m_TW_Sales_Office> dlts = (m_TW_Sales_Office.status == "1").List<m_TW_Sales_Office>();
                    string[] sales_office = new string[dlts.Count + 1];

                    sales_office[0] = "";
                    for (int i = 0; i < dlts.Count; i++)
                    {
                        sales_office[i + 1] = dlts[i].Sales_Office;
                    }

                    StoreAPI["Sales_Office~" + Key] = sales_office;
                }

                return (string[])StoreAPI["Sales_Office~" + Key];
            }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
 
                }
                #endregion

                #region 审批环节
                else
                {
                    #region 加载数据并显示
                    TW_Value_Discount hsp = (TW_Value_Discount.process == TaskAPI.Process & TW_Value_Discount.incident == TaskAPI.Incident).ListFirst<TW_Value_Discount>();
                    if (hsp != null)
                    {
                        ApplicationNo.Text                  = hsp.ApplicationNo;
                        VD.Checked                          = hsp.VD_Checked == "1";
                        SA.Checked                          = hsp.SA_Checked == "1";
                        SA2.Checked                         = hsp.SA2_Checked == "1";
                        SA3.Checked = hsp.SA3_Checked == "1";
                        SA4.Checked = hsp.SA4_Checked == "1";
                        SA5.Checked = hsp.SA5_Checked == "1";
                        SA6.Checked = hsp.SA6_Checked == "1";
                        VD_Category.SelectedValue           = hsp.VD_Category;
                        DrpPriority.SelectedValue = hsp.DrpPriority;
                        DMO_DrpPriority.SelectedValue = hsp.DMO_DrpPriority;


                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            A_Condition_Type.Text = hsp.A_Condition_Type;
                            A_Sales_Organization.Text = hsp.A_Sales_Organization;
                            Distribution_Channel.Text = hsp.Distribution_Channel;
                            A_Sorg_DC.Checked = hsp.A_Sorg_DC == "1";
                        }
                        A_Division.SelectedValue     = hsp.A_Division;
                        A_Customer.Text = hsp.A_Customer;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            B_Condition_Type.Text = hsp.B_Condition_Type;
                            B_Sales_Organization.Text = hsp.B_Sales_Organization;
                            B_Channel.Text = hsp.B_Channel;
                            B_Sorg_DC.Checked = hsp.B_Sorg_DC == "1";
                        }
                        B_Division.SelectedValue     = hsp.B_Division;
                        B_Customer.Text = hsp.B_Customer;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            C_Condition_Type.Text = hsp.C_Condition_Type;
                            C_Sales_Organization.Text = hsp.C_Sales_Organization;
                            C_Channel.Text = hsp.C_Channel;
                            C_Sorg_DC.Checked = hsp.C_Sorg_DC == "1";
                        }
                        C_Division.SelectedValue     = hsp.C_Division;
                        C_Customer.Text = hsp.C_Customer;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            D_Condition_Type.Text = hsp.D_Condition_Type;
                            D_Sales_Organization.Text = hsp.D_Sales_Organization;
                            D_Channel.Text = hsp.D_Channel;
                            D_Sorg_DC.Checked = hsp.D_Sorg_DC == "1";
                        }
                        D_Division.SelectedValue = hsp.D_Division;
                        D_Collective_Number.Text = hsp.D_Collective_Number;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            E_Condition_Type.Text = hsp.E_Condition_Type;
                            E_Sales_Organization.Text = hsp.E_Sales_Organization;
                            E_Channel.Text = hsp.E_Channel;
                            E_Sorg_DC.Checked = hsp.E_Sorg_DC == "1";
                        }
                        E_Division.SelectedValue = hsp.E_Division;
                        E_Collective_Number.Text = hsp.E_Collective_Number;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            F_Condition_Type.Text = hsp.F_Condition_Type;
                            F_Sales_Organization.Text = hsp.F_Sales_Organization;
                            F_Channel.Text = hsp.F_Channel;
                            F_Sorg_DC.Checked = hsp.F_Sorg_DC == "1";
                        }
                        F_Division.SelectedValue = hsp.F_Division;
                        F_Collective_Number.Text = hsp.F_Collective_Number;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            G_Condition_Type.Text = hsp.G_Condition_Type;
                            G_Sales_Organization.Text = hsp.G_Sales_Organization;
                            G_Channel.Text = hsp.G_Channel;
                            G_Sorg_DC.Checked = hsp.G_Sorg_DC == "1";
                        }
                        G_Division.SelectedValue = hsp.G_Division;
                        G_Collective_Number.Text = hsp.G_Collective_Number;
 
                    }
                    #endregion

                    #region 审批项初始化
                    switch (TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        case "Manager Approve":
                        case "Finance Manager":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;

                    }
                    #endregion
                }
                #endregion

                #region 设置控件禁启用
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD, SA, SA2, SA3, SA4, SA5, SA6, VD_Category, DrpPriority,A_Division, B_Division, C_Division, D_Division, E_Division, F_Division, G_Division, A_Customer, B_Customer, C_Customer, D_Collective_Number, E_Collective_Number, F_Collective_Number, G_Collective_Number);
                SetVisible(flg, Special_C_Add, Special_C_Delete, Special_B_Add, Special_A_Add, Special_B_Delete, Special_A_Delete, Special_D_Add, Special_D_Delete, Special_E_Add, Special_E_Delete, Special_F_Add, Special_F_Delete, Special_G_Add, Special_G_Delete);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                     foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                     foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                     foreach (Control cr in P_SA5.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA5.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P_SA6.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA6.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                }

                #endregion
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            InitControls();
            base.OnLoad(e);
        }

        public void InitControls()
        {
            bool flg = TaskAPI.IsAllowSubmit && TaskAPI.IsBeginStep;

            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("01", "Coll.No", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Coll_No", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("02", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Description", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("03", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "A_Scale_quantity", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("04", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Amount", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("05", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Unit", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("06", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Per", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("07", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Uom", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("08", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Calculat_Type", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("09", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_ScaleBasis", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("10", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Valid_From", InputType.None, null));
            gv_Discount_A.DynamicColumn.Add(new BoundColumn2("11", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "A_Valid_To", InputType.None, null));

            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("01", "Coll.No", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Coll_No", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("02", "Material", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Material", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("03", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Description", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("04", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "B_Scale_quantity", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("05", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Amount", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("06", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Unit", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("07", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Per", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("08", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Uom", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("09", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Calculat_Type", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("10", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_ScaleBasis", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("11", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Valid_From", InputType.None, null));
            gv_Discount_B.DynamicColumn.Add(new BoundColumn2("12", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "B_Valid_To", InputType.None, null));


            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("01", "Coll.No", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Coll_No", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("02", "Cust.group", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Cust_Group", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("03", "Material", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Material", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("04", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Description", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("05", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "C_Scale_quantity", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("06", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Amount", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("07", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Unit", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("08", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Per", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("09", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Uom", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("10", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Calculat_Type", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("11", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_ScaleBasis", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("12", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Valid_From", InputType.None, null));
            gv_Discount_C.DynamicColumn.Add(new BoundColumn2("13", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "C_Valid_To", InputType.None, null));

            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("01", "Customer", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Customer", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("02", "SOCustomer", BoundColumnType2.TextBox, 100, Align.Left, flg, "D_SOCustomer", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("03", "Cust.group", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Cust_Froup", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("04", "Sales Off.", BoundColumnType2.DropDownList, 60, Align.Left, flg, "D_Sales_Off", InputType.None, Sales_Office));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("05", "PH4", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_PH4", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("06", "Tin size", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Tin_Size", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("07", "Status", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Status", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("08", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Description", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("09", "Proc.stat", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Proc", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("10", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "D_Scale_quantity", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("11", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Amount", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("12", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Unit", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("13", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Per", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("14", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Uom", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("15", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Calculat_Type", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("16", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_ScaleBasis", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("17", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Valid_From", InputType.None, null));
            gv_Discount_D.DynamicColumn.Add(new BoundColumn2("18", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "D_Valid_To", InputType.None, null));

            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("01", "Customer", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Customer", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("02", "SOCustomer", BoundColumnType2.TextBox, 100, Align.Left, flg, "E_SOCustomer", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("03", "Cust.group", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Cust_Group", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("04", "Sales Off.", BoundColumnType2.DropDownList, 60, Align.Left, flg, "E_Sales_Off", InputType.None, Sales_Office));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("05", "Subgroup.", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Subgroup", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("06", "Tin size", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Tin_Size", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("07", "Status", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Status", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("08", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Description", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("09", "Proc.stat", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Proc", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("10", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "E_Scale_quantity", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("11", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Amount", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("12", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Unit", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("13", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Per", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("14", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Uom", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("15", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Calculat_Type", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("16", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_ScaleBasis", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("17", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Valid_From", InputType.None, null));
            gv_Discount_E.DynamicColumn.Add(new BoundColumn2("18", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "E_Valid_To", InputType.None, null));

            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("01", "Region", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Region", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("02", "County Code", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_County_Code", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("03", "City Code", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_City_Code", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("04", "Sales Off.", BoundColumnType2.DropDownList, 60, Align.Left, flg, "F_Sales_Off", InputType.None, Sales_Office));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("05", "PH4", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_PH4", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("06", "Tin size", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Tin_Size", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("07", "Status", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Status", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("08", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Description", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("09", "Proc.stat", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Proc", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("10", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "F_Scale_quantity", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("11", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Amount", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("12", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Unit", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("13", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Per", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("14", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Uom", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("15", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Calculat_Type", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("16", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_ScaleBasis", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("17", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Valid_From", InputType.None, null));
            gv_Discount_F.DynamicColumn.Add(new BoundColumn2("18", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "F_Valid_To", InputType.None, null));

            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("01", "Customer", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Customer", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("02", "SOCustomer", BoundColumnType2.TextBox, 100, Align.Left, flg, "G_SOCustomer", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("03", "Cust.group", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Cust_Group", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("04", "Sales Off.", BoundColumnType2.DropDownList, 60, Align.Left, flg, "G_Sales_Off", InputType.None, Sales_Office));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("05", "Matl grp 4.", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Matl", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("06", "Status", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Status", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("07", "Description", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Description", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("08", "Proc.stat", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Proc", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("09", "Scale Quantity", BoundColumnType2.TextBox, 100, Align.Left, flg, "G_Scale_quantity", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("10", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Amount", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("11", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Unit", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("12", "Per", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Per", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("13", "UoM", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Uom", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("14", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Calculat_Type", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("15", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_ScaleBasis", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("16", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Valid_From", InputType.None, null));
            gv_Discount_G.DynamicColumn.Add(new BoundColumn2("17", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "G_Valid_To", InputType.None, null));
            
            if (!Page.IsPostBack)
            {
                gv_Discount_A.Key = Key;
                gv_Discount_B.Key = Key;
                gv_Discount_C.Key = Key;
                gv_Discount_D.Key = Key;
                gv_Discount_E.Key = Key;
                gv_Discount_F.Key = Key;
                gv_Discount_G.Key = Key;
              

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    List<TW_Value_DiscountA_Gridview> sp1_s = new List<TW_Value_DiscountA_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp1_s.Add(new TW_Value_DiscountA_Gridview());
                        sp1_s[i].No = i + 1;
                    }
                    gv_Discount_A.DataSource = sp1_s;

                    List<TW_Value_DiscountB_Gridview> sp2_s = new List<TW_Value_DiscountB_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp2_s.Add(new TW_Value_DiscountB_Gridview());
                        sp2_s[i].No = i + 1;
                    }
                    gv_Discount_B.DataSource = sp2_s;

                    List<TW_Value_DiscountC_Gridview> sp3_s = new List<TW_Value_DiscountC_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp3_s.Add(new TW_Value_DiscountC_Gridview());
                        sp3_s[i].No = i + 1;
                    }
                    gv_Discount_C.DataSource = sp3_s;

                    List<TW_Value_DiscountD_Gridview> sp4_s = new List<TW_Value_DiscountD_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp4_s.Add(new TW_Value_DiscountD_Gridview());
                        sp4_s[i].No = i + 1;
                    }
                    gv_Discount_D.DataSource = sp4_s;

                    List<TW_Value_DiscountE_Gridview> sp5_s = new List<TW_Value_DiscountE_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp5_s.Add(new TW_Value_DiscountE_Gridview());
                        sp5_s[i].No = i + 1;
                    }
                    gv_Discount_E.DataSource = sp5_s;

                    List<TW_Value_DiscountF_Gridview> sp6_s = new List<TW_Value_DiscountF_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp6_s.Add(new TW_Value_DiscountF_Gridview());
                        sp6_s[i].No = i + 1;
                    }
                    gv_Discount_F.DataSource = sp6_s;

                    List<TW_Value_DiscountG_Gridview> sp7_s = new List<TW_Value_DiscountG_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp7_s.Add(new TW_Value_DiscountG_Gridview());
                        sp7_s[i].No = i + 1;
                    }
                    gv_Discount_G.DataSource = sp7_s;
                }
                #endregion

                #region 审批环节
                else
                {
                    IList<TW_Value_DiscountA_Gridview> sp1_s = (TW_Value_DiscountA_Gridview.process == TaskAPI.Process & TW_Value_DiscountA_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountA_Gridview>();
                    if (sp1_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp1_s.Add(new TW_Value_DiscountA_Gridview());
                            sp1_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_A.DataSource = sp1_s;



                    IList<TW_Value_DiscountB_Gridview> sp2_s = (TW_Value_DiscountB_Gridview.process == TaskAPI.Process & TW_Value_DiscountB_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountB_Gridview>();
                    if (sp2_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp2_s.Add(new TW_Value_DiscountB_Gridview());
                            sp2_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_B.DataSource = sp2_s;

                    IList<TW_Value_DiscountC_Gridview> sp3_s = (TW_Value_DiscountC_Gridview.process == TaskAPI.Process & TW_Value_DiscountC_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountC_Gridview>();
                    if (sp3_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp3_s.Add(new TW_Value_DiscountC_Gridview());
                            sp3_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_C.DataSource = sp3_s;

                    IList<TW_Value_DiscountD_Gridview> sp4_s = (TW_Value_DiscountD_Gridview.process == TaskAPI.Process & TW_Value_DiscountD_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountD_Gridview>();
                    if (sp4_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp4_s.Add(new TW_Value_DiscountD_Gridview());
                            sp4_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_D.DataSource = sp4_s;

                    IList<TW_Value_DiscountE_Gridview> sp5_s = (TW_Value_DiscountE_Gridview.process == TaskAPI.Process & TW_Value_DiscountE_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountE_Gridview>();
                    if (sp5_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp5_s.Add(new TW_Value_DiscountE_Gridview());
                            sp5_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_E.DataSource = sp5_s;

                    IList<TW_Value_DiscountF_Gridview> sp6_s = (TW_Value_DiscountF_Gridview.process == TaskAPI.Process & TW_Value_DiscountF_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountF_Gridview>();
                    if (sp6_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp6_s.Add(new TW_Value_DiscountF_Gridview());
                            sp6_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_F.DataSource = sp6_s;

                    IList<TW_Value_DiscountG_Gridview> sp7_s = (TW_Value_DiscountG_Gridview.process == TaskAPI.Process & TW_Value_DiscountG_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountG_Gridview>();
                    if (sp7_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp7_s.Add(new TW_Value_DiscountG_Gridview());
                            sp7_s[i].No = i + 1;
                        }
                    }
                    gv_Discount_G.DataSource = sp7_s;

                }
                #endregion
            }
            //SetVisible(flg, SEFI_1_Add, SEFI_2_Add);
        }
        #endregion  
        
        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }
                    
                    TaskAPI.Summary = (VD_Category.SelectedItem.Text.Split(',').Length >= 2 ? VD_Category.SelectedItem.Text.Split(',')[1].Trim() : VD_Category.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / ZK32-A " : "") + (SA.Checked ? " / ZK32-B  " : "") + (SA2.Checked ? " / ZK32-C  " : "") + (SA3.Checked ? " / ZK32-D  " : "") + (SA4.Checked ? " / ZK32-E  " : "") + (SA5.Checked ? " / ZK32-F  " : "") + (SA6.Checked ? " / ZK32-G  " : "");

                    TaskAPI["Actions"]        = VD_Category.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == VD_Category.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    //m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    //if (oc != null)
                    //{
                    //    TaskAPI["R_Manager_Approve"] = oc.WinID;
                    //}

                   

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

               

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        TW_Value_Discount hsp = new TW_Value_Discount();
                        if ((TW_Value_Discount.process == TaskAPI.Process & TW_Value_Discount.incident == TaskAPI.Incident & TW_Value_Discount.userName == UserAPI.UserName).Count<TW_Value_Discount>() > 0)
                        {
                            hsp = (TW_Value_Discount.process == TaskAPI.Process & TW_Value_Discount.incident == TaskAPI.Incident & TW_Value_Discount.userName == UserAPI.UserName).ListFirst<TW_Value_Discount>();
                        }
                        else
                        {
                            hsp.Process = TaskAPI.Process;
                            hsp.Incident = TaskAPI.Incident;
                            hsp.UserName = UserAPI.UserName;
                            hsp.UserFullName = UserAPI.UserFullName;
                            hsp.ApplicationNo = ApplicationNo.Text;
                            hsp.Time = System.DateTime.Now;
                            hsp.Status = 0;
                            hsp.Department = UserAPI.Department;
                        }

                        hsp.VD_Category       = VD_Category.SelectedValue;
                        hsp.DrpPriority = DrpPriority.SelectedValue;
                        hsp.VD_Checked        = VD.Checked ? "1" : "0";
                        hsp.SA_Checked        = SA.Checked ? "1" : "0";
                        hsp.SA2_Checked       = SA2.Checked ? "1" : "0";
                        hsp.SA3_Checked = SA3.Checked ? "1" : "0";
                        hsp.SA4_Checked = SA4.Checked ? "1" : "0";
                        hsp.SA5_Checked = SA5.Checked ? "1" : "0";
                        hsp.SA6_Checked = SA6.Checked ? "1" : "0";

                       
                      
                        #region VD
                        if (VD.Checked)
                        {
                            hsp.A_Condition_Type = A_Condition_Type.Text;
                            hsp.A_Sales_Organization = A_Sales_Organization.Text;
                            hsp.Distribution_Channel = Distribution_Channel.Text;
                            hsp.A_Division = A_Division.SelectedValue;
                            hsp.A_Customer = A_Customer.Text;
                            hsp.A_Sorg_DC = A_Sorg_DC.Checked ? "1" : "0";

                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            hsp.B_Condition_Type = B_Condition_Type.Text;
                            hsp.B_Sales_Organization = B_Sales_Organization.Text;
                            hsp.B_Channel = B_Channel.Text;
                            hsp.B_Division = B_Division.SelectedValue;
                            hsp.B_Customer = B_Customer.Text;
                            hsp.B_Sorg_DC = B_Sorg_DC.Checked ? "1" : "0";
                        }
                        #endregion

                        #region SA2
                        if (SA2.Checked)
                        {
                            hsp.C_Condition_Type = C_Condition_Type.Text;
                            hsp.C_Sales_Organization = C_Sales_Organization.Text;
                            hsp.C_Channel = C_Channel.Text;
                            hsp.C_Division = C_Division.SelectedValue;
                            hsp.C_Customer = C_Customer.Text;
                            hsp.C_Sorg_DC = C_Sorg_DC.Checked ? "1" : "0";
                        }
                        #endregion

                        #region SA3
                        if (SA3.Checked)
                        {
                            hsp.D_Condition_Type = D_Condition_Type.Text;
                            hsp.D_Sales_Organization = D_Sales_Organization.Text;
                            hsp.D_Channel = D_Channel.Text;
                            hsp.D_Division = D_Division.SelectedValue;
                            hsp.D_Collective_Number = D_Collective_Number.Text;
                            hsp.D_Sorg_DC = D_Sorg_DC.Checked ? "1" : "0";
                        }
                        #endregion

                        #region SA4
                        if (SA4.Checked)
                        {
                            hsp.E_Condition_Type = E_Condition_Type.Text;
                            hsp.E_Sales_Organization = C_Sales_Organization.Text;
                            hsp.E_Channel = E_Channel.Text;
                            hsp.E_Division = E_Division.SelectedValue;
                            hsp.E_Collective_Number = E_Collective_Number.Text;
                            hsp.E_Sorg_DC = E_Sorg_DC.Checked ? "1" : "0";

                        }
                        #endregion


                        #region SA5
                        if (SA5.Checked)
                        {
                            hsp.F_Condition_Type = F_Condition_Type.Text;
                            hsp.F_Sales_Organization = F_Sales_Organization.Text;
                            hsp.F_Channel = F_Channel.Text;
                            hsp.F_Division = F_Division.SelectedValue;
                            hsp.F_Collective_Number = F_Collective_Number.Text;
                            hsp.F_Sorg_DC = F_Sorg_DC.Checked ? "1" : "0";

                        }
                        #endregion

                        #region SA6
                        if (SA6.Checked)
                        {
                            hsp.G_Condition_Type = G_Condition_Type.Text;
                            hsp.G_Sales_Organization = G_Sales_Organization.Text;
                            hsp.G_Channel = G_Channel.Text;
                            hsp.G_Division = G_Division.SelectedValue;
                            hsp.G_Collective_Number = G_Collective_Number.Text;
                            hsp.G_Sorg_DC = G_Sorg_DC.Checked ? "1" : "0";

                        }
                        #endregion
                        
                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, hsp);
                    }
                    #endregion

                    Save();

                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion

                    #region “DMO Maintain”步骤

                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (TW_Value_Discount.process == TaskAPI.Process & TW_Value_Discount.incident == TaskAPI.Incident).Edit<TW_Value_Discount>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;

                        }
                        );
                    }
                    #endregion
                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident).Edit<hsp_SpecialPrice>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见
                    
                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }

                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    (TW_Value_Discount.process == TaskAPI.Process & TW_Value_Discount.incident == 0 & TW_Value_Discount.userName == UserAPI.UserName).Edit<TW_Value_Discount>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username== UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountA_Gridview.process == TaskAPI.Process & TW_Value_DiscountA_Gridview.incident == 0 & TW_Value_DiscountA_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountA_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountB_Gridview.process == TaskAPI.Process & TW_Value_DiscountB_Gridview.incident == 0 & TW_Value_DiscountB_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountB_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountC_Gridview.process == TaskAPI.Process & TW_Value_DiscountC_Gridview.incident == 0 & TW_Value_DiscountC_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountC_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountD_Gridview.process == TaskAPI.Process & TW_Value_DiscountD_Gridview.incident == 0 & TW_Value_DiscountD_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountD_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountE_Gridview.process == TaskAPI.Process & TW_Value_DiscountE_Gridview.incident == 0 & TW_Value_DiscountE_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountE_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountF_Gridview.process == TaskAPI.Process & TW_Value_DiscountF_Gridview.incident == 0 & TW_Value_DiscountF_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountF_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (TW_Value_DiscountG_Gridview.process == TaskAPI.Process & TW_Value_DiscountG_Gridview.incident == 0 & TW_Value_DiscountG_Gridview.userName == UserAPI.UserName).Edit<TW_Value_DiscountG_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {

            if (!VD.Checked && !SA.Checked && !SA2.Checked && !SA3.Checked && !SA4.Checked && !SA5.Checked && !SA6.Checked)
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
                VD.Checked = true;
            }
            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4, P_SA5, P_SA6);

            switch(((Anthem.CheckBox)sender).ID)
            {
                case "VD":
                    
                    if (VD.Checked)
                    {
                       // SA.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    //VD.Checked = !SA.Checked;
                    //VD.Checked = !SA2.Checked;
                    //VD.Checked = !SA3.Checked;
                    VD_L.Visible = VD.Checked;
                    break;
                
                case "SA":
                    if (SA.Checked)
                    {
                        //VD.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    SA_L.Visible = SA.Checked;
                    //if (!SA.Checked & !SA2.Checked) SA.Checked = true;
                    //SA.Checked = !VD.Checked;
                    //SA.Checked = !SA2.Checked;
                    //SA.Checked = !SA3.Checked;
                    
                    //if (!SA.Checked & SA2.Checked) { SA2_L.CssClass = "tabs1"; Tabs_Click(SA2_L, e); }
                    break;

                case "SA2":

                    if (SA2.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA2_L.Visible = SA2.Checked;
                    break;

                case "SA3":

                    if (SA3.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA3_L.Visible = SA3.Checked;
                    break;

                case "SA4":

                    if (SA4.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA4_L.Visible = SA4.Checked;
                    break;

                case "SA5":

                    if (SA5.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA5_L.Visible = SA5.Checked;
                    break;

                case "SA6":

                    if (SA6.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA6_L.Visible = SA6.Checked;
                    break;
            }
           
         
            InitTabs();
        }
        #endregion

        #region 事件 Category变换
        protected void VD_Category_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetEnable((VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3"), DrpPriority,A_Division, B_Division, C_Division, D_Division, E_Division, F_Division, A_Customer, B_Customer, C_Customer, D_Collective_Number, E_Collective_Number, F_Collective_Number, G_Collective_Number);
            
        }
        #endregion

        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4, P_SA5, P_SA6);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";
            SA5_L.CssClass = "tabs1";
            SA6_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
                case "SA2_L":
                    SA2_L.CssClass = "tabs2";
                    P_SA2.Visible = true;
                    break;
                case "SA3_L":
                    SA3_L.CssClass = "tabs2";
                    P_SA3.Visible = true;
                    break;
                case "SA4_L":
                    SA4_L.CssClass = "tabs2";
                    P_SA4.Visible = true;
                    break;
                case "SA5_L":
                    SA5_L.CssClass = "tabs2";
                    P_SA5.Visible = true;
                    break;
                case "SA6_L":
                    SA6_L.CssClass = "tabs2";
                    P_SA6.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
            SA2_L.Visible = SA2.Checked;
            SA3_L.Visible = SA3.Checked;
            SA4_L.Visible = SA4.Checked;
            SA5_L.Visible = SA5.Checked;
            SA6_L.Visible = SA6.Checked;

            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4, P_SA5, P_SA6);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";
            SA5_L.CssClass = "tabs1";
            SA6_L.CssClass = "tabs1";
        

            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

            if (SA2_L.Visible)
            {
                SA2_L.CssClass = "tabs2";
                P_SA2.Visible = true;
                return;
            }

            if (SA3_L.Visible)
            {
                SA3_L.CssClass = "tabs2";
                P_SA3.Visible = true;
                return;
            }
            if (SA4_L.Visible)
            {
                SA4_L.CssClass = "tabs2";
                P_SA4.Visible = true;
                return;
            }
            if (SA5_L.Visible)
            {
                SA5_L.CssClass = "tabs2";
                P_SA5.Visible = true;
                return;
            }

            if (SA6_L.Visible)
            {
                SA6_L.CssClass = "tabs2";
                P_SA6.Visible = true;
                return;
            }
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                
                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 Save(保存数据库)
        public void Save()
        {
            //if (!Status.IsEdited)
            //{
            //    return;
            //}

            foreach (TW_Value_DiscountA_Gridview hsp_1 in (List<TW_Value_DiscountA_Gridview>)gv_Discount_A.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_1.A_Coll_No) && string.IsNullOrEmpty(hsp_1.A_Description) && string.IsNullOrEmpty(hsp_1.A_Scale_quantity) && string.IsNullOrEmpty(hsp_1.A_Unit) && string.IsNullOrEmpty(hsp_1.A_Per) && string.IsNullOrEmpty(hsp_1.A_Uom) && string.IsNullOrEmpty(hsp_1.A_Calculat_Type) && string.IsNullOrEmpty(hsp_1.A_ScaleBasis))
                {
                    continue;
                }
                hsp_1.Process = TaskAPI.Process;
                hsp_1.Incident = TaskAPI.Incident;
                hsp_1.UserName = UserAPI.UserName;
                hsp_1.Time = System.DateTime.Now;
                hsp_1.Status = 0;
                Storage.Save(hsp_1);
            }

            foreach (TW_Value_DiscountB_Gridview hsp_2 in (List<TW_Value_DiscountB_Gridview>)gv_Discount_B.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_2.B_Coll_No) && string.IsNullOrEmpty(hsp_2.B_Description) && string.IsNullOrEmpty(hsp_2.B_Scale_quantity) && string.IsNullOrEmpty(hsp_2.B_Unit) && string.IsNullOrEmpty(hsp_2.B_Per) && string.IsNullOrEmpty(hsp_2.B_Uom) && string.IsNullOrEmpty(hsp_2.B_Calculat_Type) && string.IsNullOrEmpty(hsp_2.B_ScaleBasis))
                {
                    continue;
                }
                hsp_2.Process = TaskAPI.Process;
                hsp_2.Incident = TaskAPI.Incident;
                hsp_2.UserName = UserAPI.UserName;
                hsp_2.Time = System.DateTime.Now;
                hsp_2.Status = 0;
                Storage.Save(hsp_2);
            }

            foreach (TW_Value_DiscountC_Gridview hsp_3 in (List<TW_Value_DiscountC_Gridview>)gv_Discount_C.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_3.C_Coll_No) && string.IsNullOrEmpty(hsp_3.C_Description) && string.IsNullOrEmpty(hsp_3.C_Cust_Group) && string.IsNullOrEmpty(hsp_3.C_Scale_quantity) && string.IsNullOrEmpty(hsp_3.C_Unit) && string.IsNullOrEmpty(hsp_3.C_Per) && string.IsNullOrEmpty(hsp_3.C_Uom) && string.IsNullOrEmpty(hsp_3.C_Calculat_Type) && string.IsNullOrEmpty(hsp_3.C_ScaleBasis))
                {
                    continue;
                }
                hsp_3.Process = TaskAPI.Process;
                hsp_3.Incident = TaskAPI.Incident;
                hsp_3.UserName = UserAPI.UserName;
                hsp_3.Time = System.DateTime.Now;
                hsp_3.Status = 0;
                Storage.Save(hsp_3);
            }


            foreach (TW_Value_DiscountD_Gridview hsp_4 in (List<TW_Value_DiscountD_Gridview>)gv_Discount_D.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_4.D_SOCustomer) && string.IsNullOrEmpty(hsp_4.D_Description) && string.IsNullOrEmpty(hsp_4.D_Scale_quantity) && string.IsNullOrEmpty(hsp_4.D_Customer) && string.IsNullOrEmpty(hsp_4.D_Cust_Froup) && string.IsNullOrEmpty(hsp_4.D_Sales_Off) && string.IsNullOrEmpty(hsp_4.D_Proc) && string.IsNullOrEmpty(hsp_4.D_Unit) && string.IsNullOrEmpty(hsp_4.D_Per) && string.IsNullOrEmpty(hsp_4.D_Uom) && string.IsNullOrEmpty(hsp_4.D_Status) && string.IsNullOrEmpty(hsp_4.D_Calculat_Type) && string.IsNullOrEmpty(hsp_4.D_ScaleBasis))
                {
                    continue;
                }
                hsp_4.Process = TaskAPI.Process;
                hsp_4.Incident = TaskAPI.Incident;
                hsp_4.UserName = UserAPI.UserName;
                hsp_4.Time = System.DateTime.Now;
                hsp_4.Status = 0;
                Storage.Save(hsp_4);
            }

            foreach (TW_Value_DiscountE_Gridview hsp_5 in (List<TW_Value_DiscountE_Gridview>)gv_Discount_E.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_5.E_SOCustomer) && string.IsNullOrEmpty(hsp_5.E_Description) && string.IsNullOrEmpty(hsp_5.E_Scale_quantity) && string.IsNullOrEmpty(hsp_5.E_Customer) && string.IsNullOrEmpty(hsp_5.E_Cust_Group) && string.IsNullOrEmpty(hsp_5.E_Sales_Off) && string.IsNullOrEmpty(hsp_5.E_Subgroup) && string.IsNullOrEmpty(hsp_5.E_Tin_Size) && string.IsNullOrEmpty(hsp_5.E_Status) && string.IsNullOrEmpty(hsp_5.E_Proc) && string.IsNullOrEmpty(hsp_5.E_Unit) && string.IsNullOrEmpty(hsp_5.E_Per) && string.IsNullOrEmpty(hsp_5.E_Uom) && string.IsNullOrEmpty(hsp_5.E_Calculat_Type) && string.IsNullOrEmpty(hsp_5.E_ScaleBasis))
                {
                    continue;
                }
                hsp_5.Process = TaskAPI.Process;
                hsp_5.Incident = TaskAPI.Incident;
                hsp_5.UserName = UserAPI.UserName;
                hsp_5.Time = System.DateTime.Now;
                hsp_5.Status = 0;
                Storage.Save(hsp_5);
            }

            foreach (TW_Value_DiscountF_Gridview hsp_6 in (List<TW_Value_DiscountF_Gridview>)gv_Discount_F.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_6.F_PH4) && string.IsNullOrEmpty(hsp_6.F_Description) && string.IsNullOrEmpty(hsp_6.F_Scale_quantity) && string.IsNullOrEmpty(hsp_6.F_Region) && string.IsNullOrEmpty(hsp_6.F_City_Code) && string.IsNullOrEmpty(hsp_6.F_County_Code) && string.IsNullOrEmpty(hsp_6.F_Sales_Off) && string.IsNullOrEmpty(hsp_6.F_Status) && string.IsNullOrEmpty(hsp_6.F_Proc) && string.IsNullOrEmpty(hsp_6.F_Unit) && string.IsNullOrEmpty(hsp_6.F_Per) && string.IsNullOrEmpty(hsp_6.F_Uom) && string.IsNullOrEmpty(hsp_6.F_Calculat_Type) && string.IsNullOrEmpty(hsp_6.F_ScaleBasis))
                {
                    continue;
                }
                hsp_6.Process = TaskAPI.Process;
                hsp_6.Incident = TaskAPI.Incident;
                hsp_6.UserName = UserAPI.UserName;
                hsp_6.Time = System.DateTime.Now;
                hsp_6.Status = 0;
                Storage.Save(hsp_6);
            }

            foreach (TW_Value_DiscountG_Gridview hsp_7 in (List<TW_Value_DiscountG_Gridview>)gv_Discount_G.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_7.G_SOCustomer) && string.IsNullOrEmpty(hsp_7.G_Description) && string.IsNullOrEmpty(hsp_7.G_Scale_quantity) && string.IsNullOrEmpty(hsp_7.G_Customer) && string.IsNullOrEmpty(hsp_7.G_Cust_Group) && string.IsNullOrEmpty(hsp_7.G_Sales_Off) && string.IsNullOrEmpty(hsp_7.G_Matl) && string.IsNullOrEmpty(hsp_7.G_Status) && string.IsNullOrEmpty(hsp_7.G_Proc) && string.IsNullOrEmpty(hsp_7.G_Unit) && string.IsNullOrEmpty(hsp_7.G_Per) && string.IsNullOrEmpty(hsp_7.G_Uom) && string.IsNullOrEmpty(hsp_7.G_Calculat_Type) && string.IsNullOrEmpty(hsp_7.G_ScaleBasis))
                {
                    continue;
                }
                hsp_7.Process = TaskAPI.Process;
                hsp_7.Incident = TaskAPI.Incident;
                hsp_7.UserName = UserAPI.UserName;
                hsp_7.Time = System.DateTime.Now;
                hsp_7.Status = 0;
                Storage.Save(hsp_7);
            }
        }
                    //TaskAPI["Material"] = SEFI_Material;


          #endregion

        #region 事件 Add(增加行)
        protected void Add_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "Special_A_Add":
                    List<TW_Value_DiscountA_Gridview> special_1_s = (List<TW_Value_DiscountA_Gridview>)gv_Discount_A.DataSource;
                    TW_Value_DiscountA_Gridview special_1 = new TW_Value_DiscountA_Gridview();
                    special_1.No = special_1_s.Count + 1;
                    special_1_s.Insert(special_1_s.Count, special_1);
                    gv_Discount_A.DataSource = special_1_s;
                    gv_Discount_A.DataBind();
                    break;

                case "Special_B_Add":
                    List<TW_Value_DiscountB_Gridview> special_2_s = (List<TW_Value_DiscountB_Gridview>)gv_Discount_B.DataSource;
                    TW_Value_DiscountB_Gridview special_2 = new TW_Value_DiscountB_Gridview();
                    special_2.No = special_2_s.Count + 1;
                    special_2_s.Insert(special_2_s.Count, special_2);
                    gv_Discount_B.DataSource = special_2_s;
                    gv_Discount_B.DataBind();
                    break;

                case "Special_C_Add":
                    List<TW_Value_DiscountC_Gridview> special_3_s = (List<TW_Value_DiscountC_Gridview>)gv_Discount_C.DataSource;
                    TW_Value_DiscountC_Gridview special_3 = new TW_Value_DiscountC_Gridview();
                    special_3.No = special_3_s.Count + 1;
                    special_3_s.Insert(special_3_s.Count, special_3);
                    gv_Discount_C.DataSource = special_3_s;
                    gv_Discount_C.DataBind();
                    break;

                case "Special_D_Add":
                    List<TW_Value_DiscountD_Gridview> special_4_s = (List<TW_Value_DiscountD_Gridview>)gv_Discount_D.DataSource;
                    TW_Value_DiscountD_Gridview special_4 = new TW_Value_DiscountD_Gridview();
                    special_4.No = special_4_s.Count + 1;
                    special_4_s.Insert(special_4_s.Count, special_4);
                    gv_Discount_D.DataSource = special_4_s;
                    gv_Discount_D.DataBind();
                    break;

                case "Special_E_Add":
                    List<TW_Value_DiscountE_Gridview> special_5_s = (List<TW_Value_DiscountE_Gridview>)gv_Discount_E.DataSource;
                    TW_Value_DiscountE_Gridview special_5 = new TW_Value_DiscountE_Gridview();
                    special_5.No = special_5_s.Count + 1;
                    special_5_s.Insert(special_5_s.Count, special_5);
                    gv_Discount_E.DataSource = special_5_s;
                    gv_Discount_E.DataBind();
                    break;

                case "Special_F_Add":
                    List<TW_Value_DiscountF_Gridview> special_6_s = (List<TW_Value_DiscountF_Gridview>)gv_Discount_F.DataSource;
                    TW_Value_DiscountF_Gridview special_6 = new TW_Value_DiscountF_Gridview();
                    special_6.No = special_6_s.Count + 1;
                    special_6_s.Insert(special_6_s.Count, special_6);
                    gv_Discount_F.DataSource = special_6_s;
                    gv_Discount_F.DataBind();
                    break;

                case "Special_G_Add":
                    List<TW_Value_DiscountG_Gridview> special_7_s = (List<TW_Value_DiscountG_Gridview>)gv_Discount_G.DataSource;
                    TW_Value_DiscountG_Gridview special_7 = new TW_Value_DiscountG_Gridview();
                    special_7.No = special_7_s.Count + 1;
                    special_7_s.Insert(special_7_s.Count, special_7);
                    gv_Discount_F.DataSource = special_7_s;
                    gv_Discount_F.DataBind();
                    break;
            }
        }
        #endregion

        #region 事件 Delete(删除行)
        protected void Delete_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "Special_A_Delete":
                    List<TW_Value_DiscountA_Gridview> special_1_s = (List<TW_Value_DiscountA_Gridview>)gv_Discount_A.DataSource;
                    IList<TW_Value_DiscountA_Gridview> Special1 = (TW_Value_DiscountA_Gridview.process == TaskAPI.Process & TW_Value_DiscountA_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountA_Gridview>();
                    if (special_1_s.Count == 1)
                    {

                        return;
                    }
                    special_1_s.RemoveAt(gv_Discount_A.ChangedRowIndex == -1 || gv_Discount_A.ChangedRowIndex >= special_1_s.Count ? special_1_s.Count - 1 : gv_Discount_A.ChangedRowIndex);
                    bool flag = false;
                    foreach (TW_Value_DiscountA_Gridview special_1 in Special1)
                    {

                        foreach (TW_Value_DiscountA_Gridview special_2 in special_1_s)
                        {
                            if (special_2.ID == special_1.ID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            Storage.Delete(special_1);
                        }
                        flag = false;
                    }
                    gv_Discount_A.DataSource = special_1_s;
                    gv_Discount_A.DataBind();
                    break;

                case "Special_B_Delete":
                    List<TW_Value_DiscountB_Gridview> special_2_s = (List<TW_Value_DiscountB_Gridview>)gv_Discount_B.DataSource;
                    IList<TW_Value_DiscountB_Gridview> special2 = (TW_Value_DiscountB_Gridview.process == TaskAPI.Process & TW_Value_DiscountB_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountB_Gridview>();
                    if (special_2_s.Count == 1)
                    {

                        return;
                    }
                    special_2_s.RemoveAt(gv_Discount_B.ChangedRowIndex == -1 || gv_Discount_B.ChangedRowIndex >= special_2_s.Count ? special_2_s.Count - 1 : gv_Discount_B.ChangedRowIndex);
                    bool flag1 = false;
                    foreach (TW_Value_DiscountB_Gridview special_2 in special2)
                    {

                        foreach (TW_Value_DiscountB_Gridview special_22 in special_2_s)
                        {
                            if (special_22.ID == special_2.ID)
                            {
                                flag1 = true;
                                break;
                            }
                        }
                        if (!flag1)
                        {
                            Storage.Delete(special_2);
                        }
                        flag1 = false;
                    }
                    gv_Discount_B.DataSource = special_2_s;
                    gv_Discount_B.DataBind();
                    break;


                case "Special_C_Delete":
                    List<TW_Value_DiscountC_Gridview> base_1_s = (List<TW_Value_DiscountC_Gridview>)gv_Discount_C.DataSource;
                    IList<TW_Value_DiscountC_Gridview> base1 = (TW_Value_DiscountC_Gridview.process == TaskAPI.Process & TW_Value_DiscountC_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountC_Gridview>();
                    if (base_1_s.Count == 1)
                    {

                        return;
                    }
                    base_1_s.RemoveAt(gv_Discount_C.ChangedRowIndex == -1 || gv_Discount_C.ChangedRowIndex >= base_1_s.Count ? base_1_s.Count - 1 : gv_Discount_C.ChangedRowIndex);
                    bool flag2 = false;
                    foreach (TW_Value_DiscountC_Gridview base_1 in base1)
                    {

                        foreach (TW_Value_DiscountC_Gridview base_2 in base_1_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            Storage.Delete(base_1);
                        }
                        flag2 = false;
                    }
                    gv_Discount_C.DataSource = base_1_s;
                    gv_Discount_C.DataBind();
                    break;

                case "Special_D_Delete":
                    List<TW_Value_DiscountD_Gridview> base_2_s = (List<TW_Value_DiscountD_Gridview>)gv_Discount_D.DataSource;
                    IList<TW_Value_DiscountD_Gridview> base2 = (TW_Value_DiscountD_Gridview.process == TaskAPI.Process & TW_Value_DiscountD_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountD_Gridview>();
                    if (base_2_s.Count == 1)
                    {

                        return;
                    }
                    base_2_s.RemoveAt(gv_Discount_D.ChangedRowIndex == -1 || gv_Discount_D.ChangedRowIndex >= base_2_s.Count ? base_2_s.Count - 1 : gv_Discount_D.ChangedRowIndex);
                    bool flag3 = false;
                    foreach (TW_Value_DiscountD_Gridview base_2 in base2)
                    {

                        foreach (TW_Value_DiscountD_Gridview base_22 in base_2_s)
                        {
                            if (base_22.ID == base_2.ID)
                            {
                                flag3 = true;
                                break;
                            }
                        }
                        if (!flag3)
                        {
                            Storage.Delete(base_2);
                        }
                        flag3 = false;
                    }
                    gv_Discount_D.DataSource = base_2_s;
                    gv_Discount_D.DataBind();
                    break;

                case "Special_E_Delete":
                    List<TW_Value_DiscountE_Gridview> base_3_s = (List<TW_Value_DiscountE_Gridview>)gv_Discount_E.DataSource;
                    IList<TW_Value_DiscountE_Gridview> base3 = (TW_Value_DiscountE_Gridview.process == TaskAPI.Process & TW_Value_DiscountE_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountE_Gridview>();
                    if (base_3_s.Count == 1)
                    {

                        return;
                    }
                    base_3_s.RemoveAt(gv_Discount_E.ChangedRowIndex == -1 || gv_Discount_E.ChangedRowIndex >= base_3_s.Count ? base_3_s.Count - 1 : gv_Discount_E.ChangedRowIndex);
                    bool flag4 = false;
                    foreach (TW_Value_DiscountE_Gridview base_3 in base3)
                    {

                        foreach (TW_Value_DiscountE_Gridview base_33 in base_3_s)
                        {
                            if (base_33.ID == base_3.ID)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                        if (!flag4)
                        {
                            Storage.Delete(base_3);
                        }
                        flag4 = false;
                    }
                    gv_Discount_E.DataSource = base_3_s;
                    gv_Discount_E.DataBind();
                    break;

                case "Special_F_Delete":
                    List<TW_Value_DiscountF_Gridview> base_4_s = (List<TW_Value_DiscountF_Gridview>)gv_Discount_F.DataSource;
                    IList<TW_Value_DiscountF_Gridview> base4 = (TW_Value_DiscountF_Gridview.process == TaskAPI.Process & TW_Value_DiscountF_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountF_Gridview>();
                    if (base_4_s.Count == 1)
                    {

                        return;
                    }
                    base_4_s.RemoveAt(gv_Discount_F.ChangedRowIndex == -1 || gv_Discount_F.ChangedRowIndex >= base_4_s.Count ? base_4_s.Count - 1 : gv_Discount_F.ChangedRowIndex);
                    bool flag5 = false;
                    foreach (TW_Value_DiscountF_Gridview base_4 in base4)
                    {

                        foreach (TW_Value_DiscountF_Gridview base_44 in base_4_s)
                        {
                            if (base_44.ID == base_4.ID)
                            {
                                flag5 = true;
                                break;
                            }
                        }
                        if (!flag5)
                        {
                            Storage.Delete(base_4);
                        }
                        flag5 = false;
                    }
                    gv_Discount_F.DataSource = base_4_s;
                    gv_Discount_F.DataBind();
                    break;

                case "Special_G_Delete":
                    List<TW_Value_DiscountG_Gridview> base_5_s = (List<TW_Value_DiscountG_Gridview>)gv_Discount_G.DataSource;
                    IList<TW_Value_DiscountG_Gridview> base5 = (TW_Value_DiscountG_Gridview.process == TaskAPI.Process & TW_Value_DiscountG_Gridview.incident == TaskAPI.Incident).List<TW_Value_DiscountG_Gridview>();
                    if (base_5_s.Count == 1)
                    {

                        return;
                    }
                    base_5_s.RemoveAt(gv_Discount_G.ChangedRowIndex == -1 || gv_Discount_G.ChangedRowIndex >= base_5_s.Count ? base_5_s.Count - 1 : gv_Discount_G.ChangedRowIndex);
                    bool flag6 = false;
                    foreach (TW_Value_DiscountG_Gridview base_5 in base5)
                    {

                        foreach (TW_Value_DiscountG_Gridview base_55 in base_5_s)
                        {
                            if (base_55.ID == base_5.ID)
                            {
                                flag6 = true;
                                break;
                            }
                        }
                        if (!flag6)
                        {
                            Storage.Delete(base_5);
                        }
                        flag6 = false;
                    }
                    gv_Discount_G.DataSource = base_5_s;
                    gv_Discount_G.DataBind();
                    break;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            List<string> vald_s = new List<string>();
            List<string> vald_s_2 = new List<string>();
            List<string> vald_s_3 = new List<string>();
            List<string> vald_s_4 = new List<string>();
            List<string> vald_s_5 = new List<string>();
            List<string> vald_s_6 = new List<string>();
            List<string> vald_s_7 = new List<string>();
            List<Regular> regs = new List<Regular>();
            
            #region VD
            
            if (VD.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, A_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, A_Customer.Text, " Customer 必填"));


                foreach (TW_Value_DiscountA_Gridview SPA in (List<TW_Value_DiscountA_Gridview>)gv_Discount_A.DataSource)
                {
                    if (string.IsNullOrEmpty(SPA.A_Coll_No) && string.IsNullOrEmpty(SPA.A_Amount) && string.IsNullOrEmpty(SPA.A_Uom) && string.IsNullOrEmpty(SPA.A_Valid_From) && string.IsNullOrEmpty(SPA.A_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPA.A_Coll_No))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Coll_No, "&nbsp;&nbsp;行" + SPA.No + ": Coll.No 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPA.A_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Amount, "&nbsp;&nbsp;行" + SPA.No + ": Amount 为必填 "));
                    }
                    //if (string.IsNullOrEmpty(SPA.A_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Unit, "&nbsp;&nbsp;行" + SPA.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPA.A_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Per, "&nbsp;&nbsp;行" + SPA.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPA.A_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Uom, "&nbsp;&nbsp;行" + SPA.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPA.A_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Valid_From, "&nbsp;&nbsp;行" + SPA.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPA.A_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.A_Valid_To, "&nbsp;&nbsp;行" + SPA.No + ": Valid To 为必填 "));
                    }
                }
                
            }
            vald_s = Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>ZK32-A</b></font>");
            }
            #endregion

            #region SA
            regs.Clear();
            if (SA.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, B_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, B_Customer.Text, " Customer 必填"));

                foreach (TW_Value_DiscountB_Gridview SPB in (List<TW_Value_DiscountB_Gridview>)gv_Discount_B.DataSource)
                {
                    if (string.IsNullOrEmpty(SPB.B_Coll_No) && string.IsNullOrEmpty(SPB.B_Amount) && string.IsNullOrEmpty(SPB.B_Material)  && string.IsNullOrEmpty(SPB.B_Valid_From) && string.IsNullOrEmpty(SPB.B_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPB.B_Coll_No))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Coll_No, "&nbsp;&nbsp;行" + SPB.No + ": Coll.No 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPB.B_Material))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Material, "&nbsp;&nbsp;行" + SPB.No + ": Material 为必填 "));
                    }
                   
                    if (string.IsNullOrEmpty(SPB.B_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Amount, "&nbsp;&nbsp;行" + SPB.No + ": Amount 为必填 "));
                    }
                    //if (string.IsNullOrEmpty(SPB.B_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Unit, "&nbsp;&nbsp;行" + SPB.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPB.B_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Per, "&nbsp;&nbsp;行" + SPB.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPB.B_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Uom, "&nbsp;&nbsp;行" + SPB.No + ": Uom 为必填 "));
                    //}

                    if (string.IsNullOrEmpty(SPB.B_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Valid_From, "&nbsp;&nbsp;行" + SPB.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPB.B_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.B_Valid_To, "&nbsp;&nbsp;行" + SPB.No + ": Valid To 为必填 "));
                    }

                }

            }
            vald_s_2 = Validation(regs);
            if (vald_s_2.Count > 0)
            {
                vald_s_2.Insert(0, "<font color='#0000FF'><b>ZK32-B</b></font>");
                vald_s.AddRange(vald_s_2);
            }
            #endregion

            #region SA2
            regs.Clear();
            if (SA2.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, C_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, C_Customer.Text, " Subordinate Cusomter 必填"));

                foreach (TW_Value_DiscountC_Gridview SPC in (List<TW_Value_DiscountC_Gridview>)gv_Discount_C.DataSource)
                {

                    if (string.IsNullOrEmpty(SPC.C_Coll_No) && string.IsNullOrEmpty(SPC.C_Amount) && string.IsNullOrEmpty(SPC.C_Material) && string.IsNullOrEmpty(SPC.C_Valid_From) && string.IsNullOrEmpty(SPC.C_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPC.C_Coll_No))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Coll_No, "&nbsp;&nbsp;行" + SPC.No + ": Coll.No. 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPC.C_Material))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Material, "&nbsp;&nbsp;行" + SPC.No + ": Material 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPC.C_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Amount, "&nbsp;&nbsp;行" + SPC.No + ": Amount 为必填 "));
                    }
                    // if (string.IsNullOrEmpty(SPC.C_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Unit, "&nbsp;&nbsp;行" + SPC.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPC.C_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Per, "&nbsp;&nbsp;行" + SPC.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPC.C_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Uom, "&nbsp;&nbsp;行" + SPC.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPC.C_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Valid_From, "&nbsp;&nbsp;行" + SPC.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.C_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.C_Valid_To, "&nbsp;&nbsp;行" + SPC.No + ": Valid To 为必填 "));
                    }

                }
            }
            vald_s_3 = Validation(regs);
            if (vald_s_3.Count > 0)
            {
                vald_s_3.Insert(0, "<font color='#0000FF'><b>ZK32-C</b></font>");
                vald_s.AddRange(vald_s_3);
            }
            #endregion

            #region SA3
            regs.Clear();
            if (SA3.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, D_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, D_Collective_Number.Text, " Collective Number 必填"));

                foreach (TW_Value_DiscountD_Gridview SPD in (List<TW_Value_DiscountD_Gridview>)gv_Discount_D.DataSource)
                {

                    if (string.IsNullOrEmpty(SPD.D_SOCustomer) && string.IsNullOrEmpty(SPD.D_Amount) && string.IsNullOrEmpty(SPD.D_Tin_Size) && string.IsNullOrEmpty(SPD.D_PH4)  && string.IsNullOrEmpty(SPD.D_Valid_From) && string.IsNullOrEmpty(SPD.D_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPD.D_SOCustomer))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_SOCustomer, "&nbsp;&nbsp;行" + SPD.No + ": SOCustomer 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPD.D_Tin_Size))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Tin_Size, "&nbsp;&nbsp;行" + SPD.No + ": Tin Size 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPD.D_PH4))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_PH4, "&nbsp;&nbsp;行" + SPD.No + ": PH4 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPD.D_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Amount, "&nbsp;&nbsp;行" + SPD.No + ": Amount 为必填 "));
                    }
                    // if (string.IsNullOrEmpty(SPD.D_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Unit, "&nbsp;&nbsp;行" + SPD.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPD.D_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Per, "&nbsp;&nbsp;行" + SPD.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPD.D_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Uom, "&nbsp;&nbsp;行" + SPD.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPD.D_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Valid_From, "&nbsp;&nbsp;行" + SPD.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPD.D_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPD.D_Valid_To, "&nbsp;&nbsp;行" + SPD.No + ": Valid To 为必填 "));
                    }

                }
            }
            vald_s_4 = Validation(regs);
            if (vald_s_4.Count > 0)
            {
                vald_s_4.Insert(0, "<font color='#0000FF'><b>ZK32-D</b></font>");
                vald_s.AddRange(vald_s_4);
            }
            #endregion

            #region SA4
            regs.Clear();
            if (SA4.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, E_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, E_Collective_Number.Text, " Collective Number 必填"));

                foreach (TW_Value_DiscountE_Gridview SPE in (List<TW_Value_DiscountE_Gridview>)gv_Discount_E.DataSource)
                {

                    if (string.IsNullOrEmpty(SPE.E_SOCustomer) && string.IsNullOrEmpty(SPE.E_Amount)&& string.IsNullOrEmpty(SPE.E_Valid_From) && string.IsNullOrEmpty(SPE.E_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPE.E_SOCustomer))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_SOCustomer, "&nbsp;&nbsp;行" + SPE.No + ": SOCustomer 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPE.E_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Amount, "&nbsp;&nbsp;行" + SPE.No + ": Amount 为必填 "));
                    }
                    //if (string.IsNullOrEmpty(SPE.E_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Unit, "&nbsp;&nbsp;行" + SPE.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPE.E_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Per, "&nbsp;&nbsp;行" + SPE.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPE.E_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Uom, "&nbsp;&nbsp;行" + SPE.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPE.E_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Valid_From, "&nbsp;&nbsp;行" + SPE.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPE.E_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPE.E_Valid_To, "&nbsp;&nbsp;行" + SPE.No + ": Valid To 为必填 "));
                    }

                }
            }
            vald_s_5 = Validation(regs);
            if (vald_s_5.Count > 0)
            {
                vald_s_5.Insert(0, "<font color='#0000FF'><b>ZK32-E</b></font>");
                vald_s.AddRange(vald_s_5);
            }
            #endregion

            #region SA5
            regs.Clear();
            if (SA5.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, F_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, F_Collective_Number.Text, " Collective Number 必填"));

                foreach (TW_Value_DiscountF_Gridview SPF in (List<TW_Value_DiscountF_Gridview>)gv_Discount_F.DataSource)
                {

                    if (string.IsNullOrEmpty(SPF.F_Amount) && string.IsNullOrEmpty(SPF.F_Tin_Size) && string.IsNullOrEmpty(SPF.F_PH4) && string.IsNullOrEmpty(SPF.F_Valid_From) && string.IsNullOrEmpty(SPF.F_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPF.F_PH4))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_PH4, "&nbsp;&nbsp;行" + SPF.No + ": PH4 为必填 "));
                    }
                    if (string.IsNullOrEmpty(SPF.F_Tin_Size))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Tin_Size, "&nbsp;&nbsp;行" + SPF.No + ": Tin Size 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPF.F_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Amount, "&nbsp;&nbsp;行" + SPF.No + ": Amount 为必填 "));
                    }
                    //if (string.IsNullOrEmpty(SPF.F_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Unit, "&nbsp;&nbsp;行" + SPF.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPF.F_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Per, "&nbsp;&nbsp;行" + SPF.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPF.F_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Uom, "&nbsp;&nbsp;行" + SPF.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPF.F_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Valid_From, "&nbsp;&nbsp;行" + SPF.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPF.F_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPF.F_Valid_To, "&nbsp;&nbsp;行" + SPF.No + ": Valid To 为必填 "));
                    }

                }
            }
            vald_s_6 = Validation(regs);
            if (vald_s_6.Count > 0)
            {
                vald_s_6.Insert(0, "<font color='#0000FF'><b>ZK32-F</b></font>");
                vald_s.AddRange(vald_s_6);
            }
            #endregion

            #region SA6
            regs.Clear();
            if (SA6.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty,G_Division.SelectedValue, " Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, G_Collective_Number.Text, " Collective Number 必填"));

                foreach (TW_Value_DiscountG_Gridview SPG in (List<TW_Value_DiscountG_Gridview>)gv_Discount_G.DataSource)
                {

                    if (string.IsNullOrEmpty(SPG.G_Amount) && string.IsNullOrEmpty(SPG.G_SOCustomer) && string.IsNullOrEmpty(SPG.G_Valid_From) && string.IsNullOrEmpty(SPG.G_Valid_To))
                    {
                        continue;
                    }


                    if (string.IsNullOrEmpty(SPG.G_SOCustomer))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_SOCustomer, "&nbsp;&nbsp;行" + SPG.No + ": SOCustomer 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPG.G_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Amount, "&nbsp;&nbsp;行" + SPG.No + ": Amount 为必填 "));
                    }
                    //if (string.IsNullOrEmpty(SPG.G_Unit))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Unit, "&nbsp;&nbsp;行" + SPG.No + ": Unit 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPG.G_Per))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Per, "&nbsp;&nbsp;行" + SPG.No + ": Per 为必填 "));
                    //}

                    //if (string.IsNullOrEmpty(SPG.G_Uom))
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Uom, "&nbsp;&nbsp;行" + SPG.No + ": Uom 为必填 "));
                    //}
                    if (string.IsNullOrEmpty(SPG.G_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Valid_From, "&nbsp;&nbsp;行" + SPG.No + ": Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPG.G_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPG.G_Valid_To, "&nbsp;&nbsp;行" + SPG.No + ": Valid To 为必填 "));
                    }

                }
            }
            vald_s_7 = Validation(regs);
            if (vald_s_7.Count > 0)
            {
                vald_s_7.Insert(0, "<font color='#0000FF'><b>ZK32-G</b></font>");
                vald_s.AddRange(vald_s_7);
            }
            #endregion

            return vald_s;
        }
        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

       

        

       
    }
}